package com.edu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.bean.CommonResult;
import com.edu.bean.Page;
import com.edu.bean.Upkeep;
import com.edu.service.UpkeepService;
import com.edu.service.impl.UpkeepServiceImpl;
import com.fasterxml.jackson.annotation.JsonFormat;
@WebServlet("/upkeep.do")
public class UpkeepServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		UpkeepService us = new UpkeepServiceImpl();
		Upkeep upkeep = new Upkeep();
		int pageNum,pageSize;
		try {
			pageNum = Integer.parseInt(req.getParameter("pageNum"));
		} catch (Exception e) {
			pageNum = 1;
			// TODO: handle exception
		}
		try {
			pageSize = Integer.parseInt(req.getParameter("pageSize"));
		} catch (Exception e) {
			// TODO: handle exception
			pageSize = 10;
		}
		Page<Upkeep> upkeepPage = us.selectUpkeepAll(upkeep, pageNum, pageSize);
		CommonResult result = new CommonResult();
		result.setCode(200);
		result.setMessage("success");
		result.setData(upkeepPage);
		resp.setContentType("application/json;charset=utf-8");
		resp.getWriter().write(result.toJsonString());
	}
}
